@using Application.Service.Auth
@using Application.Web.Core.Services
@using Application.Web.Entry.Pages
@using Furion
@inject AuthService AuthService
@inject IHostEnvironment Env
@inject LockScreen LockScreenService
@inject IConfiguration Configuration

<BootstrapBlazorRoot>
    @if (AuthService.IsAuthenticated)
    {
        <Router AppAssembly="@typeof(App).Assembly">
            <Found Context="routeData">
                <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
            </Found>
            <NotFound>
                <LayoutView Layout="@typeof(MainLayout)">
                    <p>Sorry, there's nothing at this address.</p>
                </LayoutView>
            </NotFound>
        </Router>
    }
    else
    {
        <Login />
    }
</BootstrapBlazorRoot>

<!-- 锁屏模态框 -->
@if (IsLockScreenEnabled)
{
    <CustomLockScreen />
}

@code {
    private bool IsLockScreenEnabled;

    protected override async Task OnInitializedAsync()
    {
        // 读取appsettings.json中的LockScreen:Enabled配置
        IsLockScreenEnabled = Furion.App.GetConfig<bool>("LockScreen:Enabled");
        await base.OnInitializedAsync();
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            if (IsLockScreenEnabled)
            {
                await LockScreenService.InitializeAsync();
            }
        }
    }
}
